package com.hunan.api.catv.service.biz.live;

import cn.hutool.core.lang.UUID;
import cn.hutool.core.net.URLEncoder;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import cn.hutool.crypto.symmetric.AES;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.hunan.api.catv.common.CacheKey;
import com.hunan.api.catv.common.CacheName;
import com.hunan.api.catv.common.Constants;
import com.hunan.api.catv.common.ConstantsMsg;
import com.hunan.api.catv.entity.ServiceResult;
import com.hunan.api.catv.entity.dto.MemberTryWatchLiveRuleDto;
import com.hunan.api.catv.entity.dto.NewYearPartyDTO;
import com.hunan.api.catv.entity.enums.ColumnEnum;
import com.hunan.api.catv.entity.enums.Week;
import com.hunan.api.catv.entity.po.Live;
import com.hunan.api.catv.entity.po.MemberRight;
import com.hunan.api.catv.entity.vo.ColumnVo;
import com.hunan.api.catv.entity.vo.LiveVo;
import com.hunan.api.catv.mq.MqConstants;
import com.hunan.api.catv.service.ResultService;
import com.hunan.api.catv.service.biz.cache.CacheBiz;
import com.hunan.api.catv.service.biz.column.ColumnBiz;
import com.hunan.api.catv.service.biz.iptv.IptvBiz;
import com.hunan.api.catv.service.biz.mq.MqBiz;
import com.hunan.api.catv.service.biz.system.SystemDictBiz;
import com.hunan.api.catv.service.biz.tencent_cloud.im.ImBiz;
import com.hunan.api.catv.service.impl.live.LiveService;
import com.hunan.api.catv.utils.*;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;
import org.springframework.util.ObjectUtils;

import java.security.PublicKey;
import java.text.MessageFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.TimeUnit;

@CacheConfig(cacheNames = CacheName.live)
@Service
public class LiveBiz extends ResultService {

    private static final String DEFAULT_RIGHT_CODE = "R000000";
    private static final Integer NORMAL_STATE = 1;
    private static final Integer NOT_DELETED = 1;
    private static final String MEMBER_TRY_WATCH_RULE = "member_try_watch_rule";
    private static final String NEW_YEAR_PARTY_LIVE_CONF = "new_year_party_live_conf";

    @Autowired
    LiveService liveService;

    @Autowired
    LiveBiz liveBiz;

    @Autowired
    CacheBiz cacheBiz;

    @Autowired
    MqBiz mqBiz;

    @Autowired
    ImBiz imBiz;

    @Autowired
    IptvBiz iptvBiz;

    @Autowired
    ColumnBiz columnBiz;

    @Autowired
    RedisUtils redisUtils;

    @Autowired
    SystemDictBiz systemDictBiz;

    @Value("${openapi.rsa.privateKey}")
    private String privateKeyStr;

    @Value("${openapi.rsa.publicKey}")
    private String publicKeyStr;

    @Value("${openapi.aes.key}")
    private String aesKey;

    private String publicKeyStrV2 = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCiJxLUhy80TmpGev8DgqNFJTTkAbYxu+K+pkVu+WbMPNEJ8qK3KnYomXtTCcZHO0OrSe7llxKjah+5wXL72Qqgq06F/toDX9czkNX+BFJRSZQ/oG2ih7YKxP2aPwNK74vV60Mzlao63sEmfjYyhzdoAPVy5eH73Usdkl7lh0EWOQIDAQAB";
    private String privateKeyStrV2 = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKInEtSHLzROakZ6/wOCo0UlNOQBtjG74r6mRW75Zsw80QnyorcqdiiZe1MJxkc7Q6tJ7uWXEqNqH7nBcvvZCqCrToX+2gNf1zOQ1f4EUlFJlD+gbaKHtgrE/Zo/A0rvi9XrQzOVqjrewSZ+NjKHN2gA9XLl4fvdSx2SXuWHQRY5AgMBAAECgYBuF7lhMqeKC/N8BuY9q+TOfYR7ie35tmcsqhdaUVrKMEB9UI/JbLrstchViL1mf4ZiNcBNgVTWPqdrpzw6YhIkD30c2e4B99FaZEC7jVYwg34FLgMWKA7bP3G0WL/+C81hKzo0Wx3SbCarPaDg3eRwahzKnhe6XSErB2pXddkiQQJBAM3tzRfFoMyn0oSXZKUMPEVrVaZ4bdj4ziQmyIz+4LstirQY1VsDPEcMEBNfETmbfNEWF2T2jBLPVs24udYPCAcCQQDJlGKbt7YIoDk/o2YEf8/UHdFUNuhl/QK8kI+KgF8XHymomgfx02DZGtscP82iRHpWjQjehji3FgK8yy66lN+/AkEAviYd4hx/jVpNnlc4/NoecS9aSDwdmmKr3l/dgav8EXpNAF2J7N9A8o2l7m0zN5FmoJ6YfYbW8qt3iMBRAOKiUwJAeWiVu5P6X1ehI2MWnr8cPXV4DnDDqCmq7EdlLNYEb7ilLpcXEd9uBVTXgzwqbgEwbdCj9uKAZkUrgOofSuE/oQJAHKVn1xr1n0S2EmwHIC1k5uxuHfVG63EjADy7ZRY2+He/1Cw0zo78ROs2L5pgxGfqpLmcmp9r+w6JnirmXo1Ubg==";

    public PageInfo<LiveVo> adminPage(Integer pageNum, Integer pageSize, Integer type, Integer state, Integer columnId, Integer liveStatus, Integer isTop, String title) {
        Live live = new Live();
        ColumnVo cVo = columnBiz.info(columnId);
        if (!ObjectUtils.isEmpty(cVo) && "全部".equals(cVo.getTitle())) {
            columnId = null;
        }
        live.setColumnId(columnId);
        live.setContentType(type);
        live.setState(state);
        live.setLiveStatus(liveStatus);
        live.setIsTop(isTop);
        live.setTitle(title);
        PageHelper.startPage(pageNum, pageSize);
        List<LiveVo> list = liveService.list(live);
        for (LiveVo liveVo : list) {
            ColumnVo columnVo = columnBiz.info(liveVo.getColumnId());
            if (!ObjectUtils.isEmpty(columnVo)) {
                liveVo.setColumn(columnVo.getTitle());
                ;
            }
        }
        return new PageInfo<LiveVo>(list);
    }

    public ServiceResult add(Live live) {
        if (ColumnEnum.live.getCode().equals(live.getContentType()) ) {
            Integer openChat = live.getOpenChat();
            if (1 == openChat) {
                ServiceResult creatGroupResult = imBiz.createGroup(live.getTitle());
                if (!creatGroupResult.getStatus()) {
                    return creatGroupResult;
                }
                live.setGroupId(creatGroupResult.getData().toString());
            }
            Long nowSecond = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));
            live.setLiveStatus(2);
            if (live.getStartTime() > nowSecond) {
                live.setLiveStatus(0);
            }
            if (live.getStartTime() < nowSecond && live.getEndTime() > nowSecond) {
                live.setLiveStatus(1);
            }
        }
        ServiceResult addResult = liveService.add(live);
        if (addResult.getStatus()) {
            return addResult;
        }
        return buildFail(ConstantsMsg.admin_add_fail);
    }

    public ServiceResult update(Live live) {
        if (ColumnEnum.live.getCode().equals(live.getContentType()) ) {
            LiveVo liveVo = liveService.getById(live.getLiveId());
            if (1 == liveVo.getOpenChat() && 0 == live.getOpenChat()) {
                ServiceResult destoryResult = imBiz.destoryGroup(liveVo.getGroupId());
                if (!destoryResult.getStatus()) {
                    return destoryResult;
                }
                live.setGroupId("");
            }
            if (0 == liveVo.getOpenChat() && 1 == live.getOpenChat()) {
                ServiceResult createResult = imBiz.createGroup(live.getTitle());
                if (!createResult.getStatus()) {
                    return createResult;
                }
                live.setGroupId(createResult.getData().toString());
            }
            Long nowSecond = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));
            live.setLiveStatus(2);
            if (live.getStartTime() > nowSecond) {
                live.setLiveStatus(0);
            }
            if (live.getStartTime() < nowSecond && live.getEndTime() > nowSecond) {
                live.setLiveStatus(1);
            }
        }
        ServiceResult editResult = liveService.update(live);
        if (editResult.getStatus()) {
            String simpleInfoKey = MessageFormat.format(CacheName.liveInfo, String.valueOf(live.getLiveId()));
            cacheBiz.flushCacheInfo("liveInfoCache?" + live.getLiveId(), simpleInfoKey);
            return editResult;
        }
        return buildFail(ConstantsMsg.admin_edit_fail);
    }

    public ServiceResult updateState(Integer liveId, Integer state) {
        Live live = new Live();
        live.setLiveId(liveId);
        live.setState(state);
        ServiceResult editResult = liveService.update(live);
        if (editResult.getStatus()) {
            String simpleInfoKey = MessageFormat.format(CacheName.liveInfo, String.valueOf(live.getLiveId()));
            cacheBiz.flushCacheInfo("liveInfoCache?" + live.getLiveId(), simpleInfoKey);
            return editResult;
        }
        return buildFail(ConstantsMsg.admin_edit_fail);
    }

    public ServiceResult updateTop(Integer liveId, Integer isTop) {
        Live live = new Live();
        live.setLiveId(liveId);
        live.setIsTop(isTop);
        ServiceResult editResult = liveService.update(live);
        if (editResult.getStatus()) {
            String simpleInfoKey = MessageFormat.format(CacheName.liveInfo, String.valueOf(live.getLiveId()));
            cacheBiz.flushCacheInfo("liveInfoCache?" + live.getLiveId(), simpleInfoKey);
            return editResult;
        }
        return buildFail(ConstantsMsg.admin_edit_fail);
    }

    public ServiceResult editStatus(Integer liveId, Integer liveStatus) {
        Live live = new Live();
        live.setLiveId(liveId);
        live.setLiveStatus(liveStatus);
        ServiceResult editResult = liveService.update(live);
        if (editResult.getStatus()) {
            String simpleInfoKey = MessageFormat.format(CacheName.liveInfo, String.valueOf(live.getLiveId()));
            cacheBiz.flushCacheInfo("liveInfoCache?" + live.getLiveId(), simpleInfoKey);
            return editResult;
        }
        return buildFail(ConstantsMsg.admin_edit_fail);
    }

    public ServiceResult dataSync() {
        JsonArray dataResult = iptvBiz.queryTelecastList(150, 1, "", "");
        if (!ObjectUtils.isEmpty(dataResult)) {
            Live l = new Live();
            l.setContentType(ColumnEnum.tv.getCode());
            ServiceResult delResult = liveService.batchDelete(l);
            if (delResult.getStatus()) {
                Integer size = dataResult.size();
                for (int i = 0; i < size; i++) {
                    JsonObject obj = dataResult.get(i).getAsJsonObject();
                    String subCategories = obj.get("subCategories").getAsString();
                    if (ObjectUtils.isEmpty(subCategories)) {
                        continue;
                    }
                    String channelId = obj.get("channelId").getAsString();
                    String title = obj.get("title").getAsString();
                    String descHead = obj.get("descHead").getAsString();
                    String thumb1 = obj.get("thumb1").getAsString();
                    String thumb0 = obj.get("thumb0").getAsString();
                    if ("省内,全部,卫视".equals(subCategories)) {
                        subCategories = subCategories.replace("省内", "");
                    }
                    subCategories = subCategories.replace(",", "").replace("全部", "");
                    Integer columnId = columnBiz.getIdbyTitle(subCategories);
                    if (!ObjectUtils.isEmpty(columnId)) {
                        Live live = new Live();
                        live.setTitle(title);
                        live.setChannelId(channelId);
                        live.setDescription(descHead);
                        live.setCover(thumb1);
                        live.setColumnId(columnId);
                        live.setState(1);
                        live.setLiveStatus(1);
                        live.setIcon(thumb0);
                        live.setContentType(ColumnEnum.tv.getCode());
                        liveService.add(live);
                    }
                }
            }
            return buildOK(ConstantsMsg.admin_add_success);
        }
        return buildFail(ConstantsMsg.admin_add_fail);
    }

    public ServiceResult liveSync() {
        JsonArray dataResult = iptvBiz.queryTelecastList(200, 1, "", "");
        if (!ObjectUtils.isEmpty(dataResult)) {
            Live l = new Live();
            l.setContentType(ColumnEnum.live.getCode());
            ServiceResult delResult = liveService.batchDelete(l);
            if (delResult.getStatus()) {
                Integer size = dataResult.size();
                for (int i = 0; i < size; i++) {
                    JsonObject obj = dataResult.get(i).getAsJsonObject();
                    String subCategories = obj.get("subCategories").getAsString();
                    if (ObjectUtils.isEmpty(subCategories) || subCategories.contains("慢直播")) {
                        String channelId = obj.get("channelId").getAsString();
                        String title = obj.get("title").getAsString();
                        String descHead = obj.get("descHead").getAsString();
                        Live live = new Live();
                        live.setTitle(title);
                        live.setChannelId(channelId);
                        live.setDescription(descHead);
                        live.setColumnId(0);
                        live.setState(1);
                        live.setLiveStatus(1);
                        live.setContentType(ColumnEnum.live.getCode());
                        liveService.add(live);
                    }
                }
            }
            return buildOK(ConstantsMsg.admin_add_success);
        }
        return buildFail(ConstantsMsg.admin_add_fail);
    }

    public LiveVo getById(Integer liveId) {
        return liveService.getById(liveId);
    }

    @Cacheable(unless = "#result == null")
    public LiveVo info(Integer liveId) {
        LiveVo l = liveService.getById(liveId);
        if (!ObjectUtils.isEmpty(l)) {
            String shareLinkdomain = cacheBiz.getSystemDict(Constants.shareLink_domain);
            l.setShareLink(shareLinkdomain + "/h5?liveId=" + l.getLiveId());
        }
        return l;
    }

    @Cacheable(unless = "#result == null")
    public PageInfo<LiveVo> apiPage(Integer columnId, Integer contentType, Integer liveStatus, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Live live = new Live();
        ColumnVo cVo = columnBiz.info(columnId);
        if (!ObjectUtils.isEmpty(cVo) && "全部".equals(cVo.getTitle())) {
            columnId = null;
        } else {
            live.setColumnId(columnId == -1 ? null : columnId);
        }
        live.setContentType(contentType);
        live.setLiveStatus(liveStatus);
        live.setState(1);
        live.setIsTop(0);
        List<LiveVo> list = liveService.list(live);
        if (!ObjectUtils.isEmpty(list)) {
            List<String> columnList = Arrays.asList(cacheBiz.getSystemDict(Constants.no_ca_column));
            for (int i = 0; i < list.size(); i++) {
                LiveVo l = list.get(i);
                if (ColumnEnum.tv.getCode().equals(l.getContentType())) {
                    ColumnVo columnVo = columnBiz.info(l.getColumnId());
                    if (!ObjectUtils.isEmpty(columnVo)) {
                        if (columnList.contains(columnVo.getTitle())) {
                            l.setNeedsBind(false);
                        }
                    }
                }
                String shareLinkdomain = cacheBiz.getSystemDict(Constants.shareLink_domain);
                l.setShareLink(shareLinkdomain + "/h5?liveId=" + l.getLiveId());
            }
        }
        return new PageInfo<LiveVo>(list);
    }

    @Cacheable(unless = "#result == null")
    public PageInfo<LiveVo> apiPage(Integer columnId, Integer contentType, Integer liveStatus, Integer pageNum, Integer pageSize, Integer memberId) {
        PageHelper.startPage(pageNum, pageSize);
        Live live = new Live();
        ColumnVo cVo = columnBiz.info(columnId);
        if (!ObjectUtils.isEmpty(cVo) && "全部".equals(cVo.getTitle())) {
            columnId = null;
        } else {
            live.setColumnId(columnId == -1 ? null : columnId);
        }
        live.setContentType(contentType);
        live.setLiveStatus(liveStatus);
        live.setState(1);
        live.setIsTop(0);
        List<LiveVo> list = liveService.list(live);
        if (!ObjectUtils.isEmpty(list)) {
            List<String> columnList = Arrays.asList(cacheBiz.getSystemDict(Constants.no_ca_column));
            for (int i = 0; i < list.size(); i++) {
                LiveVo l = list.get(i);
                if (ColumnEnum.tv.getCode().equals(l.getContentType())) {
                    memberRightCheck(memberId, l);
                    ColumnVo columnVo = columnBiz.info(l.getColumnId());
                    if (!ObjectUtils.isEmpty(columnVo)) {
                        if (columnList.contains(columnVo.getTitle())) {
                            l.setNeedsBind(false);
                        }
                    }
                }
                String shareLinkdomain = cacheBiz.getSystemDict(Constants.shareLink_domain);
                l.setShareLink(shareLinkdomain + "/h5?liveId=" + l.getLiveId());
            }
        }
        return new PageInfo<LiveVo>(list);
    }

    private void memberRightCheck(Integer memberId, LiveVo l) {
        MemberTryWatchLiveRuleDto memberTryWatchRuleDto = JSONUtil.toBean(systemDictBiz.getStringByKey(MEMBER_TRY_WATCH_RULE), MemberTryWatchLiveRuleDto.class);
        if (memberTryWatchRuleDto != null) {
            Boolean globalTryWatchSwitch = Boolean.valueOf(Optional.ofNullable(memberTryWatchRuleDto.getGlobalTryWatchSwitch()).orElse("false"));
            if (globalTryWatchSwitch) {
                String beginTimeEndTime = (String) redisUtils.hget("member_try_watch_key", "member" + memberId);
                MemberRight memberRight = null;
                LocalDateTime beginTime = null;
                LocalDateTime endTime = null;
                if (beginTimeEndTime != null) {
                    String[] split = beginTimeEndTime.split("-");
                    beginTime = LocalDateTime.parse(split[0], DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
                    endTime = LocalDateTime.parse(split[1], DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
                } else {
                    memberRight = new MemberRight().selectOne(new QueryWrapper<MemberRight>().
                            eq(MemberRight.MEMBER_ID, memberId).
                            eq(MemberRight.RIGHT_CODE, DEFAULT_RIGHT_CODE).
                            eq(MemberRight.STATE, NORMAL_STATE).
                            eq(MemberRight.DELETED, NOT_DELETED));
                }
                if (beginTime == null && endTime == null && memberRight != null) {
                    beginTime = LocalDateTime.ofInstant(memberRight.getBeginTime().toInstant(), ZoneId.systemDefault());
                    endTime = LocalDateTime.ofInstant(memberRight.getEndTime().toInstant(), ZoneId.systemDefault());
                    if (beginTime != null && endTime != null) {
                        redisUtils.hset("member_try_watch_key", "member" + memberId, beginTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + "-" + endTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")));
                    }
                }
                if (beginTime != null && endTime != null) {
                    LocalDateTime now = LocalDateTime.now();
                    if (now.compareTo(beginTime) >= 0 && now.compareTo(endTime) <= 0) {
                        l.setNeedsBind(false);
                    }
                }
            }
        }
    }

    @Cacheable(unless = "#result == null")
    public List<LiveVo> topPage(Integer columnId, Integer contentType, Integer liveStatus) {
        Live live = new Live();
        live.setColumnId(columnId == -1 ? null : columnId);
        live.setContentType(contentType);
        live.setLiveStatus(liveStatus);
        live.setState(1);
        live.setIsTop(1);
        List<LiveVo> list = liveService.list(live);
        if (!ObjectUtils.isEmpty(list)) {
            List<String> columnList = Arrays.asList(cacheBiz.getSystemDict(Constants.no_ca_column));
            list.forEach(l -> {
                if (ColumnEnum.tv.getCode().equals(l.getContentType())) {
                    ColumnVo columnVo = columnBiz.info(columnId);
                    if (!ObjectUtils.isEmpty(columnVo)) {
                        if (columnList.contains(columnVo.getTitle())) {
                            l.setNeedsBind(false);
                        }
                    }
                }
                String shareLinkdomain = cacheBiz.getSystemDict(Constants.shareLink_domain);
                l.setShareLink(shareLinkdomain + "/h5?liveId=" + l.getLiveId());
            });
        }
        return list;
    }

    public ServiceResult playAddress(Integer type, String channelId, String ip, String startTime, String endTime, String userId) {
        if (ObjectUtils.isEmpty(userId)) {
            userId = DigestUtils.md5DigestAsHex((System.currentTimeMillis() + "WNUSER").getBytes());
        }
        String userMac = DigestUtils.md5DigestAsHex((System.currentTimeMillis() + "WNMAC").getBytes());
        JsonObject result = iptvBiz.getPlayAddressByIdWNApp(userId, ip, userMac, channelId, type, startTime, endTime);
        if (!ObjectUtils.isEmpty(result)) {
            return buildOK(result);
        }
        return buildFail(ConstantsMsg.live_getAddress_fail);
    }

    public ServiceResult p(Integer type, String channelId, String ip, String startTime, String endTime, String deviceId) {
//    	String userMac = DigestUtils.md5DigestAsHex((System.currentTimeMillis() + "WNMAC").getBytes());
        JsonObject result = iptvBiz.getPlayAddressByIdWNApp(deviceId, ip, deviceId, channelId, type, startTime, endTime);
        if (!ObjectUtils.isEmpty(result)) {
            String playAddress = result.get("playAddress").getAsString();

            String randString = UUID.fastUUID().toString(true);
            redisUtils.set("StreamRandomkey-" + randString, "1", TimeUnit.MINUTES.toSeconds(2));
            String isNeedCheck = systemDictBiz.getStringByKey("isNeedCheck");
            AES aes = new AES(aesKey.getBytes(CharsetUtil.CHARSET_UTF_8));
            randString = randString + ":" + isNeedCheck;
            String encrypt = aes.encryptBase64(randString);
            String encode = URLEncoder.ALL.encode(encrypt, CharsetUtil.CHARSET_UTF_8);
            randString = "&shit=" + encode;
            playAddress = playAddress + randString;

            playAddress = ThreeDesUtils.encode3DesBase64(playAddress.getBytes(), deviceId);
            result.addProperty("playAddress", playAddress);
            return buildOK(result, "");
        }
        return buildFail(ConstantsMsg.live_getAddress_fail);
    }

    public ServiceResult playAdr(Integer type, String channelId, String ip, String startTime, String endTime, String deviceId) {
//    	String userMac = DigestUtils.md5DigestAsHex((System.currentTimeMillis() + "WNMAC").getBytes());
        JsonObject result = iptvBiz.getPlayAddressByIdWNApp(deviceId, ip, deviceId, channelId, type, startTime, endTime);
        if (!ObjectUtils.isEmpty(result)) {
            String playAddress = result.get("playAddress").getAsString();
//            playAddress = ThreeDesUtils.encode3DesBase64(playAddress.getBytes(), deviceId);
            //-------------------------
            log.info("playAddress==：" + playAddress);
//            RSA rsa = new RSA(privateKey, publicKey);
//            playAddress = rsa.encryptBase64(playAddress, KeyType.PublicKey);
//            Map<String, byte[]> keyMap = MyRSA.generateKeyBytes();

            // 加密
            PublicKey publicKey = MyRSA.restorePublicKey(Base64.decodeBase64(publicKeyStr));
            byte[] encodedText = MyRSA.RSAEncode(publicKey, playAddress.getBytes());
            playAddress = Base64.encodeBase64String(encodedText);

//            playAddress = URLEncoder.ALL.encode(encrypt, CharsetUtil.CHARSET_UTF_8);
            //------------------------
            result.addProperty("playAddress", playAddress);
            return buildOK(result, "");
        }
        return buildFail(ConstantsMsg.live_getAddress_fail);
    }

    public ServiceResult playAdrV2(Integer type, String channelId, String ip, String startTime, String endTime, String deviceId) {
//    	String userMac = DigestUtils.md5DigestAsHex((System.currentTimeMillis() + "WNMAC").getBytes());
        JsonObject result = iptvBiz.getPlayAddressByIdWNApp(deviceId, ip, deviceId, channelId, type, startTime, endTime);
        if (!ObjectUtils.isEmpty(result)) {
            String playAddress = result.get("playAddress").getAsString();
            //-------------------------
            log.info("playAddress==：" + playAddress);

            String randString = UUID.fastUUID().toString(true);
            redisUtils.set("StreamRandomkey-" + randString, "1", TimeUnit.MINUTES.toSeconds(2));
            String isNeedCheck = systemDictBiz.getStringByKey("isNeedCheck");
            AES aes = new AES(aesKey.getBytes(CharsetUtil.CHARSET_UTF_8));
            randString = randString + ":" + isNeedCheck;
            String encrypt = aes.encryptBase64(randString);
            String encode = URLEncoder.ALL.encode(encrypt, CharsetUtil.CHARSET_UTF_8);
            randString = "&shit=" + encode;
            playAddress = playAddress + randString;
            log.info("加密前完整的播放URL：{}", playAddress);
            // 加密
            playAddress = RsaTool.encryptByPublicKey(playAddress, publicKeyStrV2);

//            playAddress = URLEncoder.ALL.encode(encrypt, CharsetUtil.CHARSET_UTF_8);
            //------------------------
            result.addProperty("playAddress", playAddress);
            return buildOK(result, "");
        }
        return buildFail(ConstantsMsg.live_getAddress_fail);
    }

    public JsonArray week() {
        JsonArray week = new JsonArray();
        LocalDateTime now = LocalDateTime.now();
        JsonObject yesterday = new JsonObject();
        String yesterdayTime = now.minusDays(1).format(DateTimeFormatter.ofPattern("yyyyMMdd"));
        String yesterdayWeek = Week.getValue(now.minusDays(1).getDayOfWeek().getValue());
        String yestdayDate = now.minusDays(1).format(DateTimeFormatter.ofPattern("MM-dd"));
        yesterday.addProperty("time", yesterdayTime);
        yesterday.addProperty("week", yesterdayWeek);
        yesterday.addProperty("date", yestdayDate);
        week.add(yesterday);
        JsonObject nowObj = new JsonObject();
        String nowTime = now.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
        String nowWeek = "今日";
        String nowDate = now.format(DateTimeFormatter.ofPattern("MM-dd"));
        nowObj.addProperty("time", nowTime);
        nowObj.addProperty("week", nowWeek);
        nowObj.addProperty("date", nowDate);
        week.add(nowObj);
        for (int i = 1; i < 6; i++) {
            String time = now.plusDays(i).format(DateTimeFormatter.ofPattern("yyyyMMdd"));
            String w = Week.getValue(now.plusDays(i).getDayOfWeek().getValue());
            String date = now.plusDays(i).format(DateTimeFormatter.ofPattern("MM-dd"));
            JsonObject obj = new JsonObject();
            obj.addProperty("time", time);
            obj.addProperty("week", w);
            obj.addProperty("date", date);
            week.add(obj);
        }
        return week;
    }

    public JsonObject schedulePage(Integer pageNum, Integer pageSize, String channelId, String time) {
        String s = time + "000000";
        LocalDateTime st = LocalDateTime.parse(s, DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
        String ns = st.minusHours(8).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
        String e = time + "235959";
        LocalDateTime se = LocalDateTime.parse(e, DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
        String ne = se.minusHours(8).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
        JsonObject result = iptvBiz.queryScheduleList(pageSize, pageNum, channelId, ns, ne);
        if (!ObjectUtils.isEmpty(result)) {
            JsonArray data = result.get("data").getAsJsonArray();
            List<JsonObject> list = GsonUtils.fromJson(GsonUtils.toJson(data), GsonUtils.getListType(JsonObject.class));
            Collections.sort(list, (a, b) -> a.get("startTime").getAsBigDecimal().compareTo(b.get("startTime").getAsBigDecimal()));
            list.forEach(l -> {
                String startTime = l.get("startTime").getAsString();
                LocalDateTime sTime = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
                String newTime = sTime.plusHours(8).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
                l.addProperty("startTime", newTime);

                String endTime = l.get("endTime").getAsString();
                LocalDateTime eTime = LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
                String newEndTime = eTime.plusHours(8).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
                l.addProperty("endTime", newEndTime);

            });
            result.add("data", GsonUtils.fromJson(list.toString(), JsonArray.class));
            return result;
        }
        return new JsonObject();
    }

    public ServiceResult xwRecommend() {
        return buildOK(redisUtils.get(CacheKey.xw_recommend));
    }

    public ServiceResult xwRecommendsave(String recommend) {
        if (!ObjectUtils.isEmpty(recommend)) {
            JsonArray array = GsonUtils.fromJson(recommend, JsonArray.class);
            for (int i = 0; i < array.size(); i++) {
                JsonObject l = array.get(i).getAsJsonObject();
                String shareLinkdomain = cacheBiz.getSystemDict(Constants.shareLink_domain);
                l.addProperty("shareLink", shareLinkdomain + "/h5?liveId=" + l.get("liveId").getAsString());
            }
            recommend = GsonUtils.toJson(array);
        }
        return buildOK(redisUtils.set(CacheKey.xw_recommend, GsonUtils.fromJson(recommend, Object.class)));
    }

    public ServiceResult exclusiveSave(Integer memberId, String title, String array) {
        String key = MessageFormat.format(CacheKey.exclusive, memberId);
        Map<Object, Object> map = new LinkedHashMap<Object, Object>();
        map.put(title, array);
        boolean flag = redisUtils.hmset(key, map);
        if (flag) {
            return buildOK(true, ConstantsMsg.live_exclusiveSave_success);
        }
        return buildFail(ConstantsMsg.live_exclusiveSave_fail);
    }

    public ServiceResult exclusiveEdit(Integer memberId, String preTitle, String title) {
        String key = MessageFormat.format(CacheKey.exclusive, memberId);
        Map<Object, Object> map = redisUtils.hmget(key);
        if (!ObjectUtils.isEmpty(map)) {
            Object obj = map.get(preTitle);
            if (!ObjectUtils.isEmpty(obj)) {
                redisUtils.del(key);
                map.entrySet().removeIf(entry -> preTitle.equals(entry.getKey().toString()));
            }
            map.put(title, obj);
            boolean flag = redisUtils.hmset(key, map);
            if (flag) {
                return buildOK(true, ConstantsMsg.live_exclusiveEdit_success);
            }
        }
        return buildFail(ConstantsMsg.live_exclusiveEdit_fail);
    }

    public ServiceResult exclusiveAll(Integer memberId) {
        String key = MessageFormat.format(CacheKey.exclusive, memberId);
        Map<Object, Object> map = redisUtils.hmget(key);
        return buildOK(map.keySet());

    }

    public ServiceResult exclusiveInfo(Integer memberId, String title) {
        String key = MessageFormat.format(CacheKey.exclusive, memberId);
        Map<Object, Object> map = redisUtils.hmget(key);
        if (!ObjectUtils.isEmpty(map)) {
            Object obj = map.get(title);
            if (!ObjectUtils.isEmpty(obj)) {
                List<JsonObject> list = GsonUtils.fromJson(obj.toString(), GsonUtils.getListType(JsonObject.class));
                Collections.sort(list, (a, b) -> a.get("startTime").getAsBigDecimal().compareTo(b.get("startTime").getAsBigDecimal()));
                return buildOK(list);
            }
        }
        return buildOK(new JsonArray());
    }

    public Long getLeftTime() {
        DateTime dateTime = DateTime.now();
        DateTime dateTimeMax = dateTime.secondOfDay().withMaximumValue();
        Long s = dateTime.getMillis();
        Long e = dateTimeMax.getMillis();
        Long t = (e - s) / 1000;
        return t;
    }

    public LiveVo getByChannelId(String channelId) {
        Live live = new Live();
        live.setChannelId(channelId);
        return liveService.get(live);
    }

    public void vodChangeNotifyV2(JsonObject body) {
        JsonArray mediaList = body.get("mediaList").getAsJsonArray();
        if (!ObjectUtils.isEmpty(mediaList)) {
            for (int i = 0; i < mediaList.size(); i++) {
                JsonObject media = mediaList.get(i).getAsJsonObject();
                String mediaId = media.get("mediaId").getAsString();
                Integer operation = media.get("operation").getAsInt();
                Integer type = media.get("type").getAsInt();
                //电视频道变更
                if (7 == type) {
                    LiveVo liveVo = liveBiz.getByChannelId(mediaId);
                    if (!ObjectUtils.isEmpty(liveVo)) {
                        Live live = new Live();
                        live.setLiveId(liveVo.getLiveId());
                        //修改
                        if (2 == operation) {
                            JsonObject liveInfo = getLive(mediaId);
                            if (!ObjectUtils.isEmpty(liveInfo)) {
                                String title = liveInfo.get("title").getAsString();
                                String descHead = liveInfo.get("descHead").getAsString();
                                String subCategories = liveInfo.get("subCategories").getAsString();
                                if ("省内,全部,卫视".equals(subCategories)) {
                                    subCategories = subCategories.replace("省内", "");
                                }
                                subCategories = subCategories.replace(",", "").replace("全部", "");
                                Integer columnId = columnBiz.getIdbyTitle(subCategories);
                                String thumb1 = liveInfo.get("thumb1").getAsString();
                                String thumb0 = liveInfo.get("thumb0").getAsString();
                                live.setTitle(title);
                                live.setDescription(descHead);
                                live.setIcon(thumb0);
                                live.setCover(thumb1);
                                live.setColumnId(columnId);
                            }
                        }
                        //删除
                        if (3 == operation) {
                            live.setState(0);
                        }
                        liveBiz.update(live);
                    }
                }
                if (type == 8) {
                    String st = media.get("st").getAsString();
                    if (!ObjectUtils.isEmpty(st)) {
                        String time = st.substring(0, 8);
                        String key = "1.100." + mediaId + "." + time;
                        mqBiz.pushFANOUT(MqConstants.local_cache_exchange, "schedulePage?" + key);
                    }

                }
            }
        }
    }

    public JsonObject getLive(String channelId) {
        JsonArray dataResult = iptvBiz.queryTelecastList(200, 1, "", "");
        if (!ObjectUtils.isEmpty(dataResult)) {
            Integer size = dataResult.size();
            for (int i = 0; i < size; i++) {
                JsonObject obj = dataResult.get(i).getAsJsonObject();
                String channelId0 = obj.get("channelId").getAsString();
                if (channelId0.equals(channelId)) {
                    return obj;
                }
            }
        }
        return null;
    }

    public ServiceResult updateSeq(Integer liveId, Integer seq) {
        Live live = new Live();
        live.setLiveId(liveId);
        live.setSeq(seq);
        ServiceResult updaterResult = liveService.update(live);
        if (updaterResult.getStatus()) {
            return buildOK(true, ConstantsMsg.admin_edit_success);
        }
        return buildFail(ConstantsMsg.admin_edit_fail);
    }

    public ServiceResult newYearParty(String pwd, String ip) {
        Map<String, Object> result = new HashMap<>();
        NewYearPartyDTO newYearParty = JSONUtil.toBean(systemDictBiz.getStringByKey(NEW_YEAR_PARTY_LIVE_CONF), NewYearPartyDTO.class);
        result.put("liveUrl", "");
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime beginTime = newYearParty.getBeginTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
        result.put("isBegin", now.isAfter(beginTime));
        LocalDateTime endTime = newYearParty.getEndTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
        result.put("isEnd", now.isAfter(endTime));
        if (StringUtils.isBlank(pwd)) {
            result.put("checkResult", false);
        } else {
            if (pwd.equalsIgnoreCase(newYearParty.getPwd())) {
                result.put("checkResult", true);
                JsonObject iptvResult = iptvBiz.getPlayAddressByIdWNApp("0:0:0:0", ip, "0:0:0:0", newYearParty.getChannelId(), 3, null, null);
                if (!ObjectUtils.isEmpty(iptvResult)) {
                    String playAddress = iptvResult.get("playAddress").getAsString();
//                result.put("liveUrl", this.p(0,newYearParty.getChannelId(),ip,beginTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),));
                    result.put("liveUrl", playAddress);
                }
            } else {
                result.put("checkResult", false);
            }
        }
        return buildOK(result);
    }

    public static void main(String[] args) {
        RSA rsa = new RSA("MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCwkAee1Tp2cIk2QuPGBw6fnpA+46e+DbsRdIuUEi5dGJEp9OxtbPvK7dQEao+Ohiim/94L+SPdBOZjBpZQMDjzxHOVOCnwgRCqUJwJcgaa3xGc+5WTXYoQGpC4NzUhklMc6vUQOYL7JsRoZpUpCJbRRtSyDW1kHk2DLQ87ruxp5oBjJwvlEsWALKfqQ5CR0awK26CKBbTfcg/mUqAzIJtBOGyOVXumA3j7DUvt1rT3wNbhbw56ZvfpoRD6yC8X/v7TgEHoe5X7JNrSSwC1XBleL+quyGIEUpsAfRK7Xc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KJo4eksfnxfiafM9dATZtnggys6z65lhKOz/vqdoV34lsFA36qxek8/gYIy8NQAwevbrDHOkG7lfGliUbxGGzTZbmh7YreF3KYEgOQSO0yFHSl+vFS9x3OTH5Zz9y8+";
        //获得私钥
//        String privateKeyBase64 = rsa.getPrivateKeyBase64();

        //获得公钥
//        String publicKeyBase64 = rsa.getPublicKeyBase64();

        //公钥加密，私钥解密
//        byte[] encrypt = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.CHARSET_UTF_8), KeyType.PublicKey);
//        String aaaa = rsa.encryptBase64("我是一段测试aaaa", KeyType.PublicKey);
//        byte[] decrypt = rsa.decrypt(encrypt, KeyType.PrivateKey);

        //私钥加密，公钥解密
//        byte[] encrypt2 = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.CHARSET_UTF_8), KeyType.PrivateKey);
//        PrivateKey privateKey = restorePrivateKey(keyMap.get("publicKey"));
//
        byte[] decrypt2 = rsa.decrypt(destr, KeyType.PrivateKey);
//        String s = rsa.decryptStr(destr, KeyType.PublicKey, CharsetUtil.CHARSET_UTF_8);
//        byte[] bytes = Base64.decodeBase64(privateStr);
//        PrivateKey privateKey = MyRSA.restorePrivateKey(bytes);
//        String s = MyRSA.RSADecode(privateKey, destr.getBytes());
    }

}
